<?php

namespace App\Observers;

use App\Models\Article;
use App\Models\Query;

/**
 * 文章表观察者
 * creating, created, updating, updated, saving, saved, deleting, deleted, restoring, restored
 * Class ArticleObserver
 * @package App\Observers
 */
class ArticleObserver
{
    use Query;

    //添加文章的时候将auth中的id放入 user_id字段
    public function creating(Article $article)
    {
        return $article->user_id = auth()->id();
    }

    /**
     * 添加文章成功，在队列中追加id
     * @param Article $article
     */
    public function created(Article $article)
    {
        $this->redisListId($article->id, 'add', 'article');

    }

    /**
     * 删除文章成功，在队列中追加id
     * @param Article $article
     */
    public function deleted(Article $article)
    {
        $this->redisListId($article->id, 'del', 'article');
    }
}
